$(function(){

    //  添加账号
    $('#batch-account-add').on('click',function(){
        checkMoney();
    });

    //  账户数量
    $('#batch-add-num').bind('input onchange', function() {
        //var num = $(this).val();
        checkMoney();
    });


    //  账号户连接数
    $('#connect').bind('input onchange', function() {
        var num  = parseInt($('#connect').val());
        if(num == '' && num <=0)
        {
            alert('非法的连接数');
        }
        checkMoney();
    });

    $('#batch-add-set-meal-primary').click(function() {
        checkMoney();
    });
    $('#batch-add-set-meal-middle').click(function() {
        checkMoney();
    });
    $('#batch-add-set-meal-height').click(function() {
        checkMoney();
    });

    //  开通时间
    $('#batch-add-date').bind('input onchange', function() {
        var date = $(this).val();
        if(date<0)
        {
            $(this).val(0);
        }
        checkMoney();
    });


    //  时间卡 类型  日  周  月
    $('#batch-add-type').bind('input onchange', function() {
        checkMoney();
    });

    //  检测money
    function checkMoney(){

        if($('#batch-add-set-meal-primary').is(':checked'))
        {
            $('#batch-add-day').val(primary_day);
            $('#batch-add-week').val(primary_week);
            $('#batch-add-month').val(primary_month);
        }


        if($('#batch-add-set-meal-middle').is(':checked'))
        {
            $('#batch-add-day').val(middle_day);
            $('#batch-add-week').val(middle_week);
            $('#batch-add-month').val(middle_month);
        }

        if($('#batch-add-set-meal-height').is(':checked'))
        {
            $('#batch-add-day').val(height_day);
            $('#batch-add-week').val(height_week);
            $('#batch-add-month').val(height_month);
        }

        var date = parseInt($('#batch-add-date').val());
        var num = parseInt($('#batch-add-num').val());
        var discount =   $('#batch-add-type option:selected').val();
        var connect_num = parseInt($('#connect').val());
        $('#batch-add-date-type').val($('#batch-add-type option:selected').text());  //   日期类型


        //variable1 !== null || variable1 !== undefined || variable1 !== '

        if(!connect_num)
        {
            $('.renew_price').text('0.00');
            $('#batch-add-price').val(0)

        }else if(!num)
        {
            $('.renew_price').text('0.00');
            $('#batch-add-price').val(0)
        }else if(!date){
            $('.renew_price').text('0.00');
            $('#batch-add-price').val(0)
        }else{
            $('.batch-price').text((date*num*discount*connect_num));
            $('#batch-add-price').val((date*num*discount*connect_num));
            $('#batch-add-date-type').val($("#batch-add-type").find("option:selected").text());

        }

    }
});